/**
 * @param {number[]} nums
 * @return {number}
 */
 var countMaxOrSubsets = function(nums) {
  const l = nums.length;
  const total = nums.reduce((a, b) => a | b);
  let ret = 0;
  let dfs = (index, val) => {
      val |= nums[index];
      if(val === total) {
          ret += 2 ** (l - index - 1);
      } else {
          index ++;
          while(index < l) {
              dfs(index, val);
              index ++;
          }
      }
  } 
  for(let i = 0; i < l; i ++) {
      dfs(i, 0);
  }
  return ret;
};

console.log(countMaxOrSubsets([3, 1]))